﻿// ***********************************************************************
// Assembly         : MVC4Portal
// Author           : Lolo
// Created          : 07-07-2013
//
// Last Modified By : Lolo
// Last Modified On : 10-22-2013
// ***********************************************************************
// <copyright file="LogXMLFileController.cs" company="">
//     Copyright (c) . All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using InnovaApp.Portals.MVC4Portal.Models.ClientFilesGenerationModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using INNOVACALL.Framework.Common.Extensions;
using System.Text;

namespace InnovaApp.Portals.MVC4Portal.Controllers.ClientFilesGenerationControllers
{
    public class LogXMLFileController : _ClientFilesGenerationControllers_Base
    {
        /// <summary>
        /// GET: /Logs/Latest.xml
        /// </summary>
        /// <returns></returns>
        [Authorize]
        public ActionResult Latest()
        {
            Response.ContentType = "text/xml";
            Response.ContentEncoding = Encoding.GetEncoding("UTF-8");
            Response.Charset = "UTF-8";
            return View(GetLogXML());
        }
        /// <summary>
        /// XMLs the content.
        /// </summary>
        /// <returns>ContentResult.</returns>
        [Authorize]
        public ContentResult XmlContent()
        {
            return Content(GetLogXML().XMLContent);
        }
        /// <summary>
        /// Gets the log XML.
        /// </summary>
        /// <returns>LogXMLFileModel.</returns>
        [Authorize]
        public LogXMLFileModel GetLogXML()
        {
            LogXMLFileModel toReturn = new LogXMLFileModel();
            string latestLogContent = Server.MapPath("/Logs/MVC4Portal.log").ReadContentFile();
            latestLogContent = latestLogContent.Replace("log4net:", "");
            string xmlHeader = @"<?xml version=""1.0"" encoding=""UTF-8"" ?><events>";
            toReturn.XMLContent = string.Format("{0}{1}</events>", xmlHeader, latestLogContent);
            return toReturn;
        }
        //To imagine a language to access older logs
    }
}
